package com.zeroone.star.sample.controller;


import com.zeroone.star.project.dto.sample.SampleDTO;
import com.zeroone.star.project.query.sample.SampleQuery;
import com.zeroone.star.project.sample.SampleApis;
import com.zeroone.star.project.vo.JsonVO;
import com.zeroone.star.sample.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Min;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 张大帅
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/user")
@Api(tags = "示例接口")
@Validated
public class UserController implements SampleApis {
    @Resource
    UserServiceImpl userService;


    /**
     * 根据条件分页查询所有
     *
     * @param condition 查询条件
     * @return 返回结果
     */
    @ApiOperation(value = "根据条件分页查询所有")
    @GetMapping("/query-all")
    @Override
    public JsonVO queryAll(@Validated SampleQuery condition) {
        return JsonVO.success(userService.listAll(condition));
    }

    @Override
    public JsonVO<SampleDTO> queryById(int id) {
        return JsonVO.success(userService.getById(id));
    }

    @ApiOperation(value = "根据ID查询")
    @GetMapping("/query-by-id")
    public JsonVO<SampleDTO> queryById02(@Min(value = 1, message = "最小值为1")
                                             @RequestParam int id) {
        return queryById(id);
    }
}

